// 动态加载导航栏
async function loadNavigation() {
  const navContainer = document.createElement('div');
  navContainer.id = 'nav-container-placeholder';

  // 使用Fetch API加载nav.html
  const response = await fetch('/static/nav.html')

  if (!response.ok) {

  }

  navContainer.innerHTML = await response.text();
  document.body.insertBefore(navContainer.firstChild, document.body.firstChild);

  InitLeaderPage();
}


function InitLeaderPage() {
  const navContainer = document.querySelector('.nav-container');
  const navButtons = document.querySelector('.nav-buttons');
  let hoverTimer;

  // 桌面端悬停控制  
  navContainer.addEventListener('mouseenter', () => {
    if (window.innerWidth > 768) {
      clearTimeout(hoverTimer);
      navButtons.style.display = 'flex';
    }
  });

  navContainer.addEventListener('mouseleave', () => {
    if (window.innerWidth > 768) {
      hoverTimer = setTimeout(() => {
        navButtons.style.display = 'none';
      }, 200); // 200ms 延迟防误触  
    }
  });

  // 移动端自动关闭  
  window.addEventListener('resize', () => {
    if (window.innerWidth <= 768) {
      navButtons.style.display = 'none';
    }
  });
}

// 页面加载完成后执行
document.addEventListener('DOMContentLoaded', loadNavigation);